package brainsplash.gyrusscope.game;

import android.content.Context;
import android.os.Vibrator;
import android.view.Display;
import android.view.WindowManager;
import brainsplash.gyrusscope.framework.Music;
import brainsplash.gyrusscope.framework.Sound;
import brainsplash.gyrusscope.framework.gl.Animation;
import brainsplash.gyrusscope.framework.gl.Font;
import brainsplash.gyrusscope.framework.gl.Texture;
import brainsplash.gyrusscope.framework.gl.TextureRegion;
import brainsplash.gyrusscope.framework.impl.GLGame;

public class Assets {
    public static Texture background;
    public static TextureRegion backgroundRegion;
    
    public static Texture items;
    public static TextureRegion mainMenu;
    public static TextureRegion pauseMenu;
    public static TextureRegion ready;
    public static TextureRegion gameOver;
    public static TextureRegion highScoresRegion;
    public static TextureRegion logo;
    public static TextureRegion soundOn;
    public static TextureRegion soundOff;
    public static TextureRegion arrow;
    public static TextureRegion pause;
    public static TextureRegion humanship;
    public static TextureRegion enemyship;
    public static TextureRegion enemyship2;
    public static TextureRegion blast;
    public static TextureRegion blast2;
    public static TextureRegion explosion;
    public static TextureRegion asteroid;
    public static TextureRegion star;
    public static Animation coinAnim;  
    public static Font font;
    
    public static Music music;
    public static Sound clickSound;
    public static Sound explodeSound;
    public static Sound laserSound;
    
    public static Display display;
    public static Vibrator vib;
    
    public static void load(GLGame game) {
        background = new Texture(game, "background.png");
        backgroundRegion = new TextureRegion(background, 0, 0, 320, 480);
        
        items = new Texture(game, "items.png");        
        mainMenu = new TextureRegion(items, 0, 224, 300, 130);
        pauseMenu = new TextureRegion(items, 224, 128, 192, 96);
        ready = new TextureRegion(items, 320, 224, 192, 32);
        gameOver = new TextureRegion(items, 352, 256, 160, 96);
        highScoresRegion = new TextureRegion(Assets.items, 0, 257, 300, 110 / 3);
        logo = new TextureRegion(items, 0, 352, 274, 142);
        soundOff = new TextureRegion(items, 0, 0, 64, 64);
        soundOn = new TextureRegion(items, 64, 0, 64, 64);
        arrow = new TextureRegion(items, 0, 64, 64, 64);
        pause = new TextureRegion(items, 64, 64, 64, 64);
        humanship = new TextureRegion(items, 128, 64, 64, 64);
        enemyship = new TextureRegion(items, 128, 128, 64, 64);
        enemyship2 = new TextureRegion(items, 64, 128, 64, 64);
        blast = new TextureRegion(items, 0, 128, 64, 64);
        blast2 = new TextureRegion(items, 128, 0, 64, 64);
        explosion = new TextureRegion(items, 0, 64, 64, 64);
        asteroid = new TextureRegion(items, 448, 448, 64, 64);
        star = new TextureRegion(items, 0, 192, 16, 16);
        
        /*coinAnim = new Animation(0.2f,                                 
                                 new TextureRegion(items, 128, 32, 32, 32),
                                 new TextureRegion(items, 160, 32, 32, 32),
                                 new TextureRegion(items, 192, 32, 32, 32),
                                 new TextureRegion(items, 160, 32, 32, 32));
        */
        
        font = new Font(items, 224, 0, 16, 16, 20);
        
        music = game.getAudio().newMusic("gyruss_stage2.mp3");
        music.setLooping(true);
        music.setVolume(0.5f);
        if(Settings.soundEnabled)
            music.play();
        clickSound = game.getAudio().newSound("click1.ogg");  
        explodeSound = game.getAudio().newSound("explosion.ogg"); 
        laserSound = game.getAudio().newSound("laser.ogg");
        

        vib = (Vibrator) game.getSystemService(Context.VIBRATOR_SERVICE);
        display = ((WindowManager) game.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    }       
    
    public static void reload() {
        background.reload();
        items.reload();
        if(Settings.soundEnabled)
            music.play();
    }
    
    public static void playSound(Sound sound) {
        if(Settings.soundEnabled)
            sound.play(0.5f);
    }
    
    public static void playSound(Sound sound, float volume) {
        if(Settings.soundEnabled)
            sound.play(volume);
    }


    public static void vibrate(int duration) {
    	vib.vibrate(duration);
    }
    
    public static int getRotation() {
		return display.getRotation();
    }
}
